home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 027a / calc14.zip / CALCHARD.PRG < prev    next >
Text File  |  1991-06-16  |  3KB  |  94 lines

  1.  
  2. // CalcHard.prg - Complex demo of the calculator
  3.  
  4. #include "inkey.ch"
  5.  
  6. Function CalcHard()
  7. Local getlist:={}, nInteger, nDontWork, nFloating, cText, nAnother
  8.  
  9.    Set Scoreboard OFF
  10.  
  11.    CLS
  12.  
  13.    Set Key K_ALT_O to Calculator
  14.  
  15.    //This will cause F2 to multiply anything by 2
  16.    SetKey(K_F2,{|p,line,var,no| If(p="CALCULATOR", no * 2, NIL)})
  17.  
  18.    //This will cause F3 to do a square root
  19.    SetKey(K_F3,{|p,line,var,no| If(p="CALCULATOR", Sqrt(no), NIL)})
  20.  
  21.    //This will cause the $ dollar sign to set fixed decimals to 2
  22.    SetKey(Asc("$"),{|p|If(p="CALCULATOR", "F2", NIL)})
  23.  
  24.    //This will cause the calc to call CalcProc() when beginning and when
  25.    // ending to display a personalized help screen.
  26.    CalcInit({|a,b,c,d,e,f,g|CalcProc(a,b,c,d,e,f,g)})
  27.  
  28.    nInteger :=7
  29.    nDontWork:=6
  30.    nAnother:=-5
  31.    nFloating:=1.23
  32.    cText    :=Space(8)
  33.  
  34.    @ 6,5 Get nInteger
  35.    @ 7,5 Get nDontWork
  36.    @ 8,5 Get nAnother
  37.    @ 9,5 Get nFloating
  38.    @10,5 Get cText
  39.  
  40.    @ 6,20 Say     "< The integer will transfer to the calculator."
  41.    @ 7,20 Say     "< You can disable the calculator on specific fields."
  42.    @ 8,20 Say     "< Negative."
  43.    @ 9,20 Say     "< Floating Point transfer and return (Ctrl-Enter)."
  44.    @10,20 Say     "< Text pasting. (press Ctrl-Enter inside calculator."
  45.  
  46.    @12,5 Say "Press ALT-O to access the calculator"
  47.  
  48.    READ
  49.  
  50. Return NIL
  51.  
  52.  
  53. Function CalcProc(cProc, nVer, cVar, nDisp, cDisp, cWhen, cColor)
  54. * cProc     = Procedure (always "CALCULATOR")
  55. * nVer      = Version number (10 through 13, for ver 1.0 through ver 1.3)
  56. * cVar      = Variable name of GET field called from
  57. * nDisp     = Numeric display of calculator
  58. * cDisp     = Character display of calculator
  59. * cWhen     = Either "INIT" when beginning calc or "END" when leaving calc
  60. * cColor    = Color when entering calculator
  61. *             * NOTE: Current color will always be "N/W", so use cColor
  62. *             *       to determine color upon entry to calculator.
  63. Static cSaveScreen
  64.  
  65.    If cWhen = "INIT"    //called going into the calculator
  66.  
  67.       //First, if this variable is "nDontWork," then abort (no calculator)
  68.       If cVar = "NDONTWORK"
  69.          Return .T.           // True = ABORT CALC
  70.       Endif
  71.  
  72.       //Everything ok, change color to W+/B (if color display)
  73.       // Also, NO need to SAVE COLOR, calculator does that.
  74.       If(IsColor(),SetColor("W+/B"),NIL)
  75.  
  76.       //Everything ok, save screen, popup help screen
  77.       cSaveScreen:=SaveScreen(0,29,5,51)
  78.       @ 0,29 to 5,51 Double
  79.       @ 1,30 Say " F2 = Display x 2    "
  80.       @ 2,30 Say " F3 = Square Root    "
  81.       @ 3,30 Say "  $ = Fix 2 decimals "
  82.       @ 4,30 Say "  H = Calculator Help"
  83.  
  84.    Else  // cWhen = "END"  //called going out of the calculator
  85.  
  86.       RestScreen(0,29,5,51,cSaveScreen)
  87.  
  88.    Endif
  89.  
  90. // (On INITIAL call from the calculator, if you return a character string,
  91. //  it will be "keyboarded" into the calculator (remember Set Typeahead).
  92.  
  93. Return "F3"  //fix decimals to 3, only good on INITIAL call.
  94.